#include "abs_factory/Factory.h"
#include "list_factory/Factory.h"
#include "table_factory/Factory.h"

#include <iostream>
#include <memory>
#include <cstring>

int main(int argc, char* argv[])
{
    // empty argument check
    if(argc < 1)
    {
        std::cerr << "Usage: " << argv[0] << " -l | -t" << std::endl;
        exit(-1);
    }
    
    std::unique_ptr<AbsFactory::Factory> factory = nullptr;
    std::string filename;

    if(!strcmp(argv[1], "-l"))
    {
        factory = std::make_unique<ListFactory::Factory>();
        filename = "ListPage";

    }else if (!strcmp(argv[1], "-t"))
    {
        factory = std::make_unique<TableFactory::Factory>();
        filename = "TablePage";
    }else
    {
        std::cerr << "Usage: " << argv[0] << " -l | -t" << std::endl;
        exit(-1);
    }

    // add links
    auto people = factory->createLink("人民日报", "http://www.people.com.cn/");
    auto gmw = factory->createLink("光明网", "http://www.gmw.cn/");

    auto bing = factory->createLink("必应", "http://cn.bing.com/");
    auto google = factory->createLink("谷歌", "http://www.google.com/");
    auto baidu = factory->createLink("百度", "http://www.baidu.com/");

    // create trays
    auto news = factory->createTray("新闻");
    news->add(people.get());
    news->add(gmw.get());

    auto search = factory->createTray("搜索");
    search->add(bing.get());
    search->add(google.get());
    search->add(baidu.get());

    // create page 
    auto page = factory->createPage(filename, "Cooder");
    page->add(news);
    page->add(search);
    page->output();
}
